﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EventReminder.Common
{
    public static class ExtensionMethods
    {
        public static bool MatchesToTheDay(this DateTime me, DateTime other)
        {
            return me.Day == other.Day && me.Month == other.Month && me.Year == other.Year;
        }

        public static bool ContainsWhiteSpace(this String me)
        {
            if (String.IsNullOrEmpty(me))
                return false;

            foreach (char c in me)
            {
                if (Char.IsWhiteSpace(c))
                    return true;
            }

            return false;
        }

        public static bool ContainsControlChars(this String me)
        {

            if (String.IsNullOrEmpty(me))
                return false;

            foreach (char c in me)
            {
                if (Char.IsControl(c))
                    return true;
            }

            return false;
        }

        public static int CountChar(this String me, char ch)
        {
            return CountChar(me, ch, false);
        }

        public static int CountChar(this String me, char ch, bool ignoreCase)
        {

            if (String.IsNullOrEmpty(me))
                return 0;

            int i = 0;
            foreach (char c in me)
            {
                if ((ignoreCase && char.ToLower(c) == char.ToLower(ch)) || (c == ch))
                    i++;
            }

            return i;
        }
    }
}
